<include file="public@header"/>
<style>
.breadcrumb {
  padding: 8px 15px;
  margin-bottom: 20px;
  list-style: none;
  background-color: #f5f5f5;
  border-radius: 4px;
  font-size: 20px;
}
.breadcrumb > li + li:before {
    color: #CCCCCC;
    content: "-> ";
    padding: 0 5px;
	font-size: 30px;
}
</style>
<link href="__STATIC__/js/bootstrap-treeview.min.css" rel="stylesheet">
<script src="__STATIC__/js/bootstrap-treeview.min.js"></script>
</head>
<body>
<div class="wrap js-check-wrap">
    <ol class="breadcrumb">
		<li><a href="{:url('Classroom/campus')}">{$param['campus_name']}</a></li>
		<li class="active">班级管理</li>
	</ol>
	<div  class="row">
		<div class="table-actions" style="margin-left:20px;">
			<input class="btn btn-primary" type="button" value="返回" onclick="javascript:history.back(-1)"></input>
			<input id="add_class" class="btn btn-primary" type="button" value="新增班级"></input>
			<input id="edit_class" class="btn btn-primary" type="button" value="编辑班级"></input>
			<input id="timetable" class="btn btn-primary" type="button" value="班级排课"></input>
			<input id="timetable_view" class="btn btn-primary" type="button" value="班级课表"></input>
			<input id="students_class" class="btn btn-primary" type="button" value="学生名单"></input>
			<input id="class_attendance" class="btn btn-primary" type="button" value="班级考勤"></input>
			<input id="class_blog" class="btn btn-primary" type="button" value="课堂资料"></input>
			
			<!-- <button id="delete_classroom" class="btn btn-danger js-ajax-submit" type="submit" style="float:right" -->
					<!-- data-action="{:url('classroom/delete_classroom')}" data-msg="您确定删除吗？">删除 -->
			<!-- </button> -->
		</div>
		<div class="col-md-3" id="tree">
		</div>
		<div class="col-md-9">
			<if condition="isset($class_info)">
			<form class="js-ajax-form" action="" method="post">
				<table class="table table-hover table-bordered table-list">
					<thead>
					<tr>
						<th width="15">
							<label>
								<input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
							</label>
						</th>
						<th>班级ID</th>
						<th>班级名称</th>
						<th>教室</th>
						<th>任课教师</th>
						<th>课次</th>
						<th>满班人数</th>
						<th>教室地图</th>
					</tr>
					</thead>
					<foreach name="class_info" item="vo">
						<tr name='{$vo.id}' hidden="hidden">
							<td>
								<input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]" value="{$vo.id}" title="ID:{$vo.id}">
							</td>
							<td><b>{$vo.id}</b></td>
							<td>{$vo.name}</td>
							<td>{$vo.classroom_id|default='未知'}</td>
							<td>{$vo.teacher|default='未知'}</td>
							<td>{$vo.class_number|default='未知'}</td>
							<td>{$vo.student_number|default='未知'}</td>
							<td>
								<if condition="isset($vo['map_img'])&&$vo['map_img']!=''">
									<img src="{:cmf_get_image_preview_url($vo['map_img'])}" height="40px;" onclick="javascript:parent.imagePreviewDialog('{:cmf_get_image_preview_url($vo['map_img'])}');"></img>
								<else>
									暂无教室地图
								</if>
							</td>
						</tr>
					</foreach>
				</table>
				<ul class="pagination">{$page|default=''}</ul>
			</form>
			</if>
		</div>
	</div>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
	function getTree() {
		// Some logic to retrieve, or generate tree structure
		var tree = {$category_tree};
		return tree;
	}
	$('#tree').treeview({data: getTree()});

	$('#tree').on('nodeSelected', function(event, data) {
	  // 事件代码...
		var e = eval(data.href);
		$("tr[name]").hide();
		$.each(e,function(key,v){
			<!-- alert(val.post_id); -->
			$("input[name='ids[]']").each(function () {
				if (($(this).is(':checked'))&&($(this).val()!=v.post_id)) {
					$("input[value='"+$(this).val()+"']").prop("checked",false);
					$("tr[name="+$(this).val()+"]").prop("class",false);
				}
			});
			$("tr[name='"+v.post_id+"']").show();
		});
	});	
	
	$(function(){
	<!-- 新增班级 -->
	$("#add_class").click(function(){
		var url = "{:url('Class/add_class','',false,true)}" + "/id/" + {$param['id']};
		window.location.href = url;
	});
	<!-- 编辑班级 -->
		$("#edit_class").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length == 1){
				var url = "{:url('Class/edit_class','',false,true)}" + "/id/" + ids;
				<!-- alert(url); -->
				window.location.href = url;
			}
			else{
				alert('请选择一个班级进行编辑');
			}
		});
		<!-- 编辑课表 -->
		$("#timetable").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length == 1){
				var url = "{:url('Class/timetable','',false,true)}" + "/id/" + ids;
				<!-- alert(url); -->
				window.location.href = url;
			}
			else{
				alert('请选择一个班级进行排课');
			}
		});
		<!-- 查看课表 -->
		$("#timetable_view").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length == 1){
				var url = "{:url('Class/class_timetable_view','',false,true)}" + "/id/" + ids;
				<!-- alert(url); -->
				window.location.href = url;
			}
			else{
				alert('请选择一个班级进行排课');
			}
		});
		<!-- 查看班级详情页 -->
		$("#students_class").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length == 1){
				$("input").prop("checked",false);
				$("tr").prop("class",false);
				var url = "{:url('admin/class/students_class','',false,true)}" + "/id/" + ids;
				window.location.href = url;
			}
			else{
				alert('请选择一个要查看的班级！');
			}
		});
		
		<!-- 查看班级考勤 -->
		$("#class_attendance").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length == 1){
				$("input").prop("checked",false);
				$("tr").prop("class",false);
				var url = "{:url('admin/class/class_attendance','',false,true)}" + "/class_id/" + ids;
				window.location.href = url;
			}
			else{
				alert('请选择一个要考勤的班级！');
			}
		});
		
		<!-- 查看班级课堂资料 -->
		$("#class_blog").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length == 1){
				$("input").prop("checked",false);
				$("tr").prop("class",false);
				var url = "{:url('admin/class/class_blog_list','',false,true)}" + "/class_id/" + ids;
				window.location.href = url;
			}
			else{
				alert('请选择一个要查看课堂资料的班级！');
			}
		});
	});

	$(function(){
		$("tr[name]").click(function(){
			var id = $(this).attr("name");
			var is_check = $("input[value='"+id+"']").prop("checked");
			if(is_check){
				$("input[value='"+id+"']").prop("checked",false);
				$(this).prop("class",false);
			}
			else{
				$("input[value='"+id+"']").prop("checked",true);
				$(this).prop("class","success");
			}
		});
	});
</script>
</body>
</html>